<?php
/**
 * @version      BOSSCMS-Free
 * @trademark    BOSSCMS
 * @copyright    Copyright © by BOSSCMS-Free (https://www.bosscms.net/) 保留所有权利
 * @license      https://gitee.com/Greenpeas/BOSSCMS/license/ 和 https://www.bosscms.net/freelicense/
 * @link         https://www.bosscms.net/
 * @author       温州软界网络技术有限公司
**/
defined('IS_OK') or exit('Access Forbidden');

into::basic_class('admin');

class content extends admin
{
	public function edit()
	{
		global $G;
		$G['cover'] = $this->cover('content');
		$id = arrExist($G['get'],'id');
		if($id){
			if(!$G['get']['column']){
				$G['body_class'] = 'iframe-content';
				$G['navsub'] = $this->navsub();
			}
			$data = mysql::select_one('*','items',"id='{$id}'");
			echo $this->theme('items/content',$data);
		}else{
			alert('没有指定栏目');
		}
	}
	
	public function add()
	{
		global $G;
		$this->cover('content','M');
		$bosscms=true;
		if(isset($G['post'])){
			$id = arrExist($G['get'],'id');
			if(is_numeric($id)){
				$data = array(
					'issub'       => arrExist($G['post'],'issub'),
					'content'     => arrExist($G['post'],'content')
				);
				if(!mysql::update($data,'items',"id='{$id}'")){
					alert('操作失败');
				}
			}
			alert('操作成功', url::mpf('items','content','edit'));
		}else{
			alert('没有提交信息');
		}
	}
	
	public function navsub()
	{
		global $G;
		$data = array();
		$items = page::items();
		foreach($items as $v){
			if($v['type']==1 && !preg_match('/group/',BOSSCMS_MOLD)){
				$data[] = array(
					'name' => $v['name'],
					'level' => $v['level'],
					'id' => $v['id'],
					'on' => $G['get']['id']==$v['id']?'on':'',
					'url' => url::mpf('items','content','edit',array('id'=>$v['id'],'items'=>null,'type'=>null,'core'=>null))
				);
			}else if(preg_match('/^(2|3|4|5)$/',$v['type']) && !preg_match('/items|layers|view/',BOSSCMS_MOLD)){
				$data[] = array(
					'name' => $v['name'],
					'level' => $v['level'],
					'id' => $v['id'],
					'on' => $G['get']['items']==$v['id']?'on':'',
					'url' => url::mpf('group',BOSSCMS_PART!='audit'?'group':'audit','init',array('items'=>$v['id'],'type'=>$v['type'],'id'=>null,'core'=>null))
				);
			}else if($v['type']!=9){
				$data[] = array(
					'name' => $v['name'],
					'level' => $v['level'],
					'id' => $v['id'],
					'on' => '',
					'url' => 'javascript:;'
				);
			}
		}
		if(preg_match('/items|layers|view/',BOSSCMS_MOLD)){
			$j = $k = 0;
			$view = $layers = array();
			$info = load::info();
			$ctrl = load::ctrl();
			foreach($ctrl as $core=>$series){
				if($series[0]){
					if(!$j){
						$view[] = array(
							'name' => '模板板块',
							'level' => 1,
							'id' => 'core',
							'on' => '',
							'url' => 'javascript:;'
						);
					}
					$view[] = array(
						'name' => setDefault($info[$core]['title'],$core),
						'level' => 2,
						'id' => $core,
						'on' => $G['get']['core']==$core?'on':'',
						'url' => url::mpf('view','view','init',array('core'=>$core,'items'=>null,'type'=>null,'id'=>null))
					);
					$j++;
				}
				if($series[88]){
					if(!$k){
						$layers[] = array(
							'name' => '模板内容',
							'level' => 1,
							'id' => 'core',
							'on' => '',
							'url' => 'javascript:;'
						);
					}
					$layers[] = array(
						'name' => setDefault($info[$core]['title'],$core),
						'level' => 2,
						'id' => $core,
						'on' => $G['get']['core']==$core?'on':'',
						'url' => url::mpf('layers','layers','init',array('core'=>$core,'items'=>null,'type'=>null,'id'=>null))
					);
					$k++;
				}
			}
			$data = array_merge($data, $view, $layers);
		}
		for($i=0; $i<=1; $i++){
			foreach($data as $k=>$v){
				if($v['url']=='javascript:;'){
					if((isset($data[$k+1]) && (($data[$k+1]['url']=='javascript:;' && $data[$k+1]['level']>=$data[$k+2]['level']) || $v['level']>=$data[$k+1]['level'])) || !isset($data[$k+1])){
						unset($data[$k]);
					}
				}
			}
		}
		return $this->theme('content/content', $data);
	}
}
?>